package spring.yongongsystem.controller.admin;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import spring.yongongsystem.POJO.dto.GroupPageQueryDTO;
import spring.yongongsystem.POJO.dto.WorkerDTO;
import spring.yongongsystem.POJO.dto.WorkerPageQueryDTO;
import spring.yongongsystem.POJO.entity.Group;
import spring.yongongsystem.result.PageResult;
import spring.yongongsystem.result.Result;
import spring.yongongsystem.service.WorkerService;
@CrossOrigin(origins = "http://localhost:5173")
@RestController("adminWorkerController")
@RequestMapping("/admin/worker")
@Api(tags = "管理员用工相关接口")
@Slf4j
public class WorkerController {
    @Autowired
    private WorkerService workerService;

    /**
     * 新增用工
     * @param workerDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增用工")
    public Result save(@RequestBody WorkerDTO workerDTO){
        log.info("新增用工：{}",workerDTO);
        workerService.save(workerDTO);
        return Result.success();
    }

    /**
     * 用工分页查询
     * @param workerPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("用工分页查询")
    public Result<PageResult> page(WorkerPageQueryDTO workerPageQueryDTO){
        log.info("用工分页查询，参数为：{}", workerPageQueryDTO);
        PageResult pageResult = workerService.pageQuery(workerPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 删除用工
     * @param id
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除用工")
    public Result<String> deleteById(Long id){
        log.info("删除用工：{}", id);
        workerService.deleteById(id);
        return Result.success();
    }

    /**
     * 编辑用工信息
     * @param workerDTO
     * @return
     */
    @PutMapping
    @ApiOperation("编辑用工信息")
    public Result update(@RequestBody WorkerDTO workerDTO){
        log.info("编辑用工信息：{}", workerDTO);
        workerService.update(workerDTO);
        return Result.success();
    }
}
